import operate from '@dfeidao/atom-nodejs/db/operate';
// import sys_date from '@dfeidao/atom-nodejs/msg/sys-date';
import uuid from 'uuid';
// import { systemid } from '../../atom/config';

// import { IBaseTable } from '@feidao/web/atom/nodejs/db/interfaces';


interface Message {
	usercode: string;
	password: string;
	user_name: string;
	name_spell: string;
	is_disabled: boolean;
	create_time: number;
	email: string;
	phone: string;
	avatar_path: string;
	avatar_name: string;
	avatar_type: string;
	productid: string;
	last_login_time: number;
	phone_verified: boolean;
	email_verified: boolean;
	is_admin: boolean;
}

export default async function atom(msg: Message, action_id: string, session_id: string, spaceid: string) {
	const systemid = '12';

	const { exec, insert } = operate(action_id, session_id, systemid);

	insert('pub_user', {
		_id: uuid(),
		usercode: msg.usercode,
		password: msg.password,
		user_name: msg.user_name,
		name_spell: msg.name_spell,
		is_disabled: msg.is_disabled,
		create_time: msg.create_time,
		email: msg.email,
		phone: msg.phone,
		avatar_path: msg.avatar_path,
		avatar_name: msg.avatar_name,
		avatar_type: msg.avatar_type,
		productid: msg.productid,
		last_login_time: msg.last_login_time,
		phone_verified: msg.phone_verified,
		email_verified: msg.email_verified,
		is_admin: msg.is_admin
	});

	const res = await exec();
	// console.log(res)
	if (res.code === 1) {
		return 'success';
	} else {
		return 'fail';
	}
}
// , last_login_time: msg.last_login_time, phone_verified: msg.phone_verified, email_verified: msg.email_verified
